<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" import="com.student.model. *" import="java.util.*"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!-- <!DOCTYPE html> -->
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<script src="https://cdn.staticfile.org/jquery/3.3.0/jquery.min.js"></script>
<link href="https://fastly.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.38/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fastly.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.38/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<link href="https://fastly.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.38/examples/navbar/navbar.css" rel="stylesheet">
<script src="https://fastly.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.38/assets/js/ie-emulation-modes-warning.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath }/css/courseList.css" type="text/css"></link>
<title>在线选课系统-超级管理员</title>
</head>
<body>
	<%
	User user = (User) request.getSession().getAttribute("info");
	// out.print(user.toString());
	%>
	
	
	<!-- 头部 -->
	<header>
		<div class="header">
			<div class="header-left">
				<img src="${ pageContext.request.contextPath }/images/selection.png"> 
				<span>在线选课系统</span>
			</div>
			<div class="header-right">
				<span>欢迎你，<%=user.getRealname() %></span> 
				<a href="javascript:void(0);" onclick="alert()">超级管理员</a>
				<span>|</span>
				<div class="logout">
					<a href="${ pageContext.request.contextPath }/LogoutServlet">安全退出</a>
					<img src="${ pageContext.request.contextPath }/images/logout.png">
				</div>
			</div>
		</div>
	</header>
	
	<!-- 表格 -->
	<div class="content">
		<div class="alert alert-info title" role="alert">
			<div>课程总览</div>
			<div>
				<%  
					Object msg = request.getAttribute("msg");
					if (msg!=null) {
						if(msg.equals("0")) out.print("<span style='color:red;'>提示：表单缺失必填项！</span>");
						else if(msg.equals("2")) out.print("<span style='color:red;'>提示：课程id已使用！</span>");
						else if (msg.equals("1")) out.print("<span style='color:#449d44;;'>提示：添加课程成功！</span>");
						else if (msg.equals("3")) out.print("<span style='color:#449d44;;'>提示：删除课程成功！</span>");
					}
				%>
				<!-- 添加课程的按钮 -->
			    <button type="button" class="btn btn-success" data-toggle="modal" data-target="#exampleModal">
			      添加课程
			    </button>
			</div>

		</div>
		<div class="table">
			<table class="table table-hover table-bordered" style="text-align:center">
			  <thead>
			    <tr>
			      <th scope="col">课程编号</th>
			      <th scope="col">课程名称</th>
			      <th scope="col">授课老师</th>
			      <th scope="col">学分</th>
			      <th scope="col">第一次上课时间</th>
			      <th scope="col">第二次上课时间</th>
			      <th scope="col">上课地点</th>
			      <th scope="col">限制人数</th>
			      <th scope="col">已选人数</th>
			      <th scope="col">操作</th>
			    </tr>
			  </thead>
			  <tbody>
			  	<c:forEach items="${courseList }" var="course">
			  		<tr>
				      <td scope="row">${course.course_id }</td>
				      <td>${course.course_name }</td>
				      <td>${course.teacher }</td>
				      <td>${course.point}</td>
				      <td>${course.time_1}</td>
				      <td>${course.time_2 }</td>
				      <td>${course.location }</td>
				      <td>${course.limited }</td>
				      <td>${course.num }</td>
				      <td>
				      	<a class="btn btn-danger btn-sm " id="delete" href="${pageContext.request.contextPath}/DelTeacherCourseServlet?course_id=${course.course_id}&num=${course.num}" role="button">删除</a>
				      </td>
				    </tr>
			  	</c:forEach>
			    
			  </tbody>
			</table>
		</div>
	</div>
	
	<!-- 添加课程的模态框 -->
    <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">添加课程</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <form action="${ pageContext.request.contextPath }/addCourseServlet" method="post">
             	<div class="row">
             		<div class="form-group col-lg-6">
		                <label for="exampleInputPassword1">课程编号</label>
		                <input type="text" class="form-control" name="course_id">
	          		</div>
	             	<div class="form-group col-lg-6">
		                <label for="exampleInputEmail1">课程名称</label>
		                <input type="text" class="form-control" name="course_name">
	              	</div>
              	</div>
              	
              	<div class="row">
              		<div class="form-group col-lg-6">
		                <label for="exampleInputPassword1">教师姓名</label>
		                <input type="text" class="form-control" name="teacher">
	          		</div>
	             	<div class="form-group col-lg-6">
		                <label for="exampleInputPassword1">学分（1~6）</label>
		                <input type="text" class="form-control" name="point">
		            </div>
              	</div>
              	
              	<div class="row">
              		<div class="form-group col-lg-6">
		                <label for="exampleFormControlSelect1">第一次上课时间：周数</label>
		                <select class="form-control" id="exampleFormControlSelect1" name="week1">
		                  <option value="1">星期一</option>
		                  <option value="2">星期二</option>
		                  <option value="3">星期三</option>
		                  <option value="4">星期四</option>
		                  <option value="5">星期五</option>
		                </select>
	          		</div>
	             	<div class="form-group col-lg-6">
		                <label for="exampleFormControlSelect2">具体时间</label>
		                <select class="form-control" id="exampleFormControlSelect2" name="hour1">
		                  <option value="1">8:05~9:50</option>
		                  <option value="2">10:15~12:00</option>
		                  <option value="3">13:35~15:20</option>
		                  <option value="4">15:45~17:30</option>
		                  <option value="5">18:30~20:45</option>
		                </select>
		            </div>
              	</div>
              	
              	<div class="row">
              		<div class="form-group col-lg-6">
		                <label for="exampleFormControlSelect3">第二次上课时间：周数</label>
		                <select class="form-control" id="exampleFormControlSelect3" name="week2">
		                  <option value="1">星期一</option>
		                  <option value="2">星期二</option>
		                  <option value="3">星期三</option>
		                  <option value="4">星期四</option>
		                  <option value="5">星期五</option>
		                </select>
	          		</div>
	             	<div class="form-group col-lg-6">
		                <label for="exampleFormControlSelect4">具体时间</label>
		                <select class="form-control" id="exampleFormControlSelect4" name="hour2">
		                  <option value="1">8:05~9:50</option>
		                  <option value="2">10:15~12:00</option>
		                  <option value="3">13:35~15:20</option>
		                  <option value="4">15:45~17:30</option>
		                  <option value="5">18:30~20:45</option>
		                </select>
		            </div>
              	</div>
              	
              	<div class="row">
              		<div class="form-group col-lg-6">
		                <label for="exampleInputPassword1">上课地点</label>
                		<input type="text" class="form-control" name="location">
	          		</div>
	             	<div class="form-group col-lg-6">
		                <label for="exampleInputPassword1">限制人数</label>
               			<input type="text" class="form-control" name="limited">
		            </div>
              	</div>
              <button type="submit" class="btn btn-primary">提交</button>
            </form>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            <!-- <button type="button" class="btn btn-primary">保存退出</button> -->
          </div>
        </div>
      </div>
    </div>

	<!-- 修改课程的模态框 -->
    <div class="modal fade" id="editModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">修改课程</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <form action="${ pageContext.request.contextPath }/addCourseServlet" method="post">
             	<div class="row">
             		<div class="form-group col-lg-6">
		                <label for="exampleInputPassword1">课程编号</label>
		                <input type="text" class="form-control" name="course_id">
	          		</div>
	             	<div class="form-group col-lg-6">
		                <label for="exampleInputEmail1">课程名称</label>
		                <input type="text" class="form-control" name="course_name">
	              	</div>
              	</div>
              	
              	<div class="row">
              		<div class="form-group col-lg-6">
		                <label for="exampleInputPassword1">教师姓名</label>
		                <input type="text" class="form-control" name="teacher">
	          		</div>
	             	<div class="form-group col-lg-6">
		                <label for="exampleInputPassword1">学分（1~6）</label>
		                <input type="text" class="form-control" name="point">
		            </div>
              	</div>
              	
              	<div class="row">
              		<div class="form-group col-lg-6">
		                <label for="exampleFormControlSelect1">第一次上课时间：周数</label>
		                <select class="form-control" id="exampleFormControlSelect1" name="week1">
		                  <option value="1">星期一</option>
		                  <option value="2">星期二</option>
		                  <option value="3">星期三</option>
		                  <option value="4">星期四</option>
		                  <option value="5">星期五</option>
		                </select>
	          		</div>
	             	<div class="form-group col-lg-6">
		                <label for="exampleFormControlSelect2">具体时间</label>
		                <select class="form-control" id="exampleFormControlSelect2" name="hour1">
		                  <option value="1">8:05~9:50</option>
		                  <option value="2">10:15~12:00</option>
		                  <option value="3">13:35~15:20</option>
		                  <option value="4">15:45~17:30</option>
		                  <option value="5">18:30~20:45</option>
		                </select>
		            </div>
              	</div>
              	
              	<div class="row">
              		<div class="form-group col-lg-6">
		                <label for="exampleFormControlSelect3">第二次上课时间：周数</label>
		                <select class="form-control" id="exampleFormControlSelect3" name="week2">
		                  <option value="1">星期一</option>
		                  <option value="2">星期二</option>
		                  <option value="3">星期三</option>
		                  <option value="4">星期四</option>
		                  <option value="5">星期五</option>
		                </select>
	          		</div>
	             	<div class="form-group col-lg-6">
		                <label for="exampleFormControlSelect4">具体时间</label>
		                <select class="form-control" id="exampleFormControlSelect4" name="hour2">
		                  <option value="1">8:05~9:50</option>
		                  <option value="2">10:15~12:00</option>
		                  <option value="3">13:35~15:20</option>
		                  <option value="4">15:45~17:30</option>
		                  <option value="5">18:30~20:45</option>
		                </select>
		            </div>
              	</div>
              	
              	<div class="row">
              		<div class="form-group col-lg-6">
		                <label for="exampleInputPassword1">上课地点</label>
                		<input type="text" class="form-control" name="location">
	          		</div>
	             	<div class="form-group col-lg-6">
		                <label for="exampleInputPassword1">限制人数</label>
               			<input type="text" class="form-control" name="limited">
		            </div>
              	</div>
              <button type="submit" class="btn btn-primary">提交</button>
            </form>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            <!-- <button type="button" class="btn btn-primary">保存退出</button> -->
          </div>
        </div>
      </div>
    </div>
    <script src="https://fastly.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
    <script src="https://fastly.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.38/dist/js/bootstrap.min.js"></script>
	<script type="text/javascript">
		 $(function() {
		  // 给删除的a标签绑定点击事件 用于删除确认提示操作
		  $("a#delete").click(function() {
		   return confirm("确认删除该课程吗？");
		  });
		 }); 
		 
		 const alert = () =>{
			window.alert('超级管理员好\(^o^)/~')
		 }
	</script>
</body>

</html>